package engine.newUi
{
	import com.greensock.TweenLite;
	
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.logic.LogSendLogic;
	import engine.logic.login.PlayCDTimerLogic;
	import engine.logic.tips.TipsManage;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.AlertUI;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	import newx.com.loader.SwfLoader;
	
	/**
	 * 拜师
	 * @author zhouqiang
	 * 
	 */	
	public class EmulateLogic
	{
		private var _ui:EmulateUI;
		
		private static var _self:EmulateLogic;
		
		private var _bind:BindManage;
		
		private var _model:ModelLocator;
		
		/**绑定武学心得个数标签*/
	//	private var _bindIndex:int	= -1;
		
		/**绑定武学心得购买次数标签*/
		//private var _bindBuyIndex:int	= -1;
		
		/**绑定伙伴经验*/
		//private var _bindpartnerExp:Object;
		
		/**武学心得个数*/
	//	private var _herbNum:int;
		
		/**武学心得最大个数*/
		private var _herbMaxNum:int	= 8;
		
		/**练功类型*/
		//private var _ExpType:int;
		
		/**伙伴ID*/
		//private var _partnerID:int;
		
		/**当前伙伴view*/
		//private var _partnerView:ObjectData;
		
		/**当前伙伴的等级*/
		//private var _partenerLevel:int;
		
		/**伙伴数据数组*/
		//private var _allPartner:Array;
		
		/**所有CD时间*/
		private var _CDtimeArr:Array;
		
		/**礼物NxClip数组*/
		private var _giftArr:Array;
		
		/**所有已开启师傅数组*/
		//private var _teacherArr:Array;
		
		//private var _maxExp:Number;
		
		//private var _exp:Number;
		
		/**刷新提示框是否显示*/
		//private var _isShow2:Boolean	= 	true;
		
		/**购买心得提示框是否显示*/
		//private var _isShow3:Boolean	= 	true;
		
		/**清除CD提示框是否显示*/
		//private var _isShow4:Boolean	= 	true;
		
		/**所有已开房子的最低等级*/
		//private var houseLevel:int		=	0;
		
		/**房子的数量*/
		//private var houseNum:int		=	1;
		
		/**开启按钮容器*/
		private var _beginBtn:MovieClip;
		
		/**名师和拜师按钮容器*/
		private var _btnMc:MovieClip;
		
		//private var btn1:SimpleButton;
		/**是否播放特效*/
		private var _isShowEff:Boolean	 =	false;
		
		/**师傅的Index*/
		private var _index:int				=	-2;
		
		private var effectMC:MovieClip;
		
		/**师傅的等级*/
		private var _emulateLevelArr:Array
		
		private var _time:Timer;
		
		private var _CDTimeCount:int;
		
		private var _tipsStr:String;
		
		/**成功拜师第几个老师*/
		private var _isShowTime:Boolean	=	false;
		
		/**成功拜师第几个老师*/
		private var _teacherindex:int	=	-1;
		
		/**是否拜师成功*/
		private var _isSucceed:Boolean	=	false;
		
		/**今天购买武学次数*/
		private var _buyherbNum:int	=	0;
		
		/**鼠标是否在购买按钮上*/
		private var _isOnBuyBtn:Boolean	=	false;
		
		public static function getInstance():EmulateLogic
		{
			if(_self == null)
			{
				_self	=	new EmulateLogic();
			}
			return _self
		}
		
		public function get ui():EmulateUI
		{
			if(_ui==null)
			{
				_ui	=	new EmulateUI();
			}
			return _ui
		}
		
		public function EmulateLogic()
		{
			
		}
		
		public function Init():void
		{
			_CDtimeArr		=	[];
			_giftArr		=	[];	
			//_teacherArr		=	[];
			_emulateLevelArr=	[];
			_time         	= 	new Timer(1000);
			_model			=	ModelLocator.getInstance();
			_bind 			=	BindManage.getInstance();
			_ui				=	EmulateUI.getInstance();
			ui.succeedEffect.visible	= false;
			InitGiftImg();
			initGroup();
			//在CD模块注册
			PlayCDTimerLogic.getInstance().resgisAll(5,checkCDTimer);
			
		//	_model.addEventListener( String(CustomToClientFlag.SERVER_CUSTOMMSG_HERB_PRICE), getPriceHandle );
			
			//心得恢复时间
			_model.addEventListener( String(CustomToClientFlag.SERVER_CUSTOMMSG_RESTORE_TIME ), onCDtimeHandle );
			
			//伙伴获得经验
			_model.addEventListener( String(CustomToClientFlag.SERVER_CUSTOMMSG_PARTNER_ADD_EXP ), partnerGetEpHandle );
			
			//绑定武学心得
//			if (_bindIndex == -1) 
//			{
//				_bindIndex	=	_bind.BindProp(_model.scene.Role, "HerbNum", this, "onHerbNumHandle");
//			}
					
		}
		
		/**
		 * 初始化开启，拜师，名师3个按钮图
		 * 
		 */		
		private function InitGiftImg():void
		{
			 _btnMc		=	ResManager.newResClass("GroupItemEffect_2") as MovieClip;
			 _beginBtn	=	ResManager.newResClass("GroupItemEffect_2") as MovieClip;
			 ui.addChild(_beginBtn)
			 //var btn3:SimpleButton	=	ResManager.newResClass("tishi08") as SimpleButton;
			 var btnmc1:MovieClip	=	_btnMc.getChildByName("btn1") as MovieClip;
			 var btnmc2:MovieClip	=	_btnMc.getChildByName("btn2") as MovieClip;
			 var beginMc:MovieClip	=	_beginBtn.getChildByName("btn3") as MovieClip;
			 //var txt3:TextField		=	new TextField();
			// txt3.mouseEnabled		=	false;
			 //txt3.htmlText			=	StaticIni.getSwfLangStr("UIString_1000223");
			// txt3.filters			=	[NxLabel.glow];
			 ui.btn1.x	=	btnmc2.x+5;
			 ui.btn1.y	=	btnmc2.y-3;
			 
			 ui.btn2.x	=	btnmc1.x;
			 ui.btn2.y	=	btnmc1.y-3;
			
			 ui.btn3.x		=	beginMc.x;
			 ui.btn3.y		=	beginMc.y;
			// txt3.x		=	beginMc.x+22;
			// txt3.y		=	beginMc.y+8;
			// ui.btn1.scaleX =	ui.btn2.scaleX =	ui.btn1.scaleX =	0.8;
			 _btnMc.addChild(ui.btn1);
			 _btnMc.addChild(ui.btn2);
			// _btnMc.addChild(ui.getExpLab);
			 _beginBtn.addChild(ui.btn3);
			 _btnMc.removeChild(	_btnMc.getChildByName("btn1"));
			 _btnMc.removeChild(	_btnMc.getChildByName("btn2"));
			 _btnMc.removeChild(	_btnMc.getChildByName("btn3"));
			 _beginBtn.removeChild(	_beginBtn.getChildByName("btn1"));
			 _beginBtn.removeChild(	_beginBtn.getChildByName("btn2"));
			 _beginBtn.removeChild(	_beginBtn.getChildByName("btn3"));
			// _beginBtn.removeChild(beginMc);
			 _btnMc.visible	=	false;
			 ui._viweGruop.addChild(_btnMc);
			 ui._viweGruop.addChild(_beginBtn);
			 //_btnMc.addChild(txt1);
			// _btnMc.addChild(txt2);
			// _beginBtn.addChild(txt3);
			 //升级师傅
			 ui.btn1.addEventListener(MouseEvent.CLICK,onUpClickHandle);
			 ui.btn1.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			 ui.btn1.addEventListener(MouseEvent.ROLL_OVER,onbtn1OverHandle);
			 
			 //打开拜师界面
			 ui.btn2.addEventListener(MouseEvent.CLICK,onOpenClickHandle);
			 ui.btn2.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			 ui.btn2.addEventListener(MouseEvent.ROLL_OVER,onbtn2OverHandle);
			 
			 //开启新队列  
			 ui.btn3.addEventListener(MouseEvent.CLICK,onOpenNewListHandle);
			 ui.btn3.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			 ui.btn3.addEventListener(MouseEvent.ROLL_OVER,onbtn3OverHandle);
			 
			 //初始化武学心得图标
			// ui.imgClip.source		=	ResourcesPath.getPropsURL(48001045);
			// ui.imgClip.addEventListener(MouseEvent.ROLL_OVER,onImgOverHandle);
			// ui.imgClip.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			 ui.explainText.htmlText	=	StaticIni.getSwfLangStr("UIString_1000232");
			 
			 ui.clearCDbtn.visible	=	false;	
			 ui.clearCDbtn.addEventListener(MouseEvent.CLICK,onClearCDHandle);
			 ui.clearCDbtn.addEventListener(MouseEvent.ROLL_OVER,onClearCDOverHandle);
			 ui.clearCDbtn.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			 //ui._viweGruop.addChild(ui.clearCDbtn);
		}
		
		/**
		 * 初始化表格 
		 * 
		 */		
		private function initGroup():void
		{
			var mc:MovieClip;
//			var btn:SimpleButton;
//			var titMc:MovieClip;	
			for(var i:int=0;i < _herbMaxNum;i++)
			{
				mc	=	ui._viweGruop.getItemByIndex(i);
				mc.addEventListener(MouseEvent.ROLL_OVER,onMouseOverHandle);
				//mc.addEventListener(MouseEvent.ROLL_OUT,onMouseOutHandle);
				mc.addEventListener(MouseEvent.CLICK,onGroupClickHandle);
				mc.buttonMode		=	false;
			}
			ui._viweGruop.addChild(ui.succeedEffect);
		}
		
		private function onGroupClickHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.currentTarget as MovieClip
			if( mc.currentFrame == 2 && !(e.target as NxButton))
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000286"));
			}		
		}
		/**
		 * 回调函数
		 * 返回练功房的CD时间，等级信息
		 * val cd时间，Array 数据
		 */
		public function checkCDTimer(val:int,arr:Array):void
		{	
			var mc:MovieClip		=	ui._viweGruop.getItemByIndex(arr[1]-1);
			mc.gotoAndStop(2);
			//titMc是师傅头像mc
			var checkMc:MovieClip 	=	mc.getChildByName("pic") as MovieClip
			var titMc:MovieClip		=	checkMc.getChildByName("tit") as MovieClip;
			var btn:SimpleButton	=	checkMc.getChildByName("btn") as SimpleButton;
			btn.useHandCursor	=	false;
			titMc.mouseEnabled	=	false;
			titMc.gotoAndStop(arr[3]);
			var timeTxt:TextField	=	checkMc.getChildByName("timetxt") as TextField;
			
			if( _index	==	arr[1]-1 )
			{
				if( val == 0 )
				{
					ui.clearCDbtn.visible	=	false;
					//_btnMc.visible			=	true;
					btnMcShow();
				}
				else
				{
					ui.clearCDbtn.visible	=	true;
					_btnMc.visible			=	false;
				}
			}
				
			if(val == 0)
			{
				timeTxt.htmlText	=	"";
			}
			else
			{
				timeTxt.htmlText	=	PlayCDTimerLogic.getInstance().getTimerStr(val,true);
			}			
			mc["data"]				=	arr[1]-1;
			_CDtimeArr[arr[1]-1]	=	val;
			//摆放“开启”按钮位置
			if(arr[1] == 8)
			{
				_beginBtn.visible	=	false
			}
			else
			{
				var Nextmc:MovieClip	=	ui._viweGruop.getItemByIndex(_CDtimeArr.length) as MovieClip;
				if(Nextmc != null)
				{
					_beginBtn.x	=	Nextmc.x;
					_beginBtn.y	=	Nextmc.y;
				}		
			}
			_emulateLevelArr[arr[1]-1]	=	arr[3];
			if(effectMC == null)return;
			// 判断是否升级了师傅
			if(_isShowEff &&(_emulateLevelArr[arr[1]-1] < arr[3]))
			{
				//mc		=	ui._viweGruop.getItemByIndex(arr[1]-1);
				_emulateLevelArr[arr[1]-1]	=	arr[3];
				onbtn1OverHandle();
				_isShowEff			=	false;
				effectMC.visible	=	true;
				effectMC.gotoAndPlay(1);
				effectMC.addFrameScript(effectMC.totalFrames - 1,mcOverHandle)
				effectMC.x	= mc.x-50;
				effectMC.y	= mc.y-58;
				if(arr[3] == 3)
				{
					(_btnMc.getChildAt(1) as NxButton).x		=	50;
					(_btnMc.getChildAt(0) as NxButton).visible	=	false;
				}
				else
				{
					(_btnMc.getChildAt(1) as NxButton).x		=	20;
					(_btnMc.getChildAt(0) as NxButton).visible	=	true;
				}
			}
		}
		
		/**
		 * 绑定武学个数 
		 * @param val
		 * 
		 */		
		public function set onHerbNumHandle(val:int):void
		{	
			//_herbNum			=	val;
			//ui.numLab.htmlText	=	StaticIni.getSwfLangStrVar("UIString_1000250",[val]);
			if(!_isOnBuyBtn)return
			//onBuyBookOverHandle();
		}
		
		/**
		 * 今天购买丹药次数 
		 * @param val
		 * 
		 */		
		public function set onHerbBuyHandle(val:int):void
		{
			_buyherbNum	=	val;
		//	if(!_isOnBuyBtn)return
			//onBuyBookOverHandle();
		}
		
		public function BeforeShow():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_PRACTISE_UI);
			ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			//ui.buyBtn.addEventListener(MouseEvent.CLICK,onBuyBookHandle);
			//ui.buyBtn.addEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
		//	ui.buyBtn.addEventListener(MouseEvent.ROLL_OVER,onBuyBookOverHandle);
			ui._viweGruop.addEventListener(MouseEvent.ROLL_OUT,onMouseOutHandle);
			var str:String	=	"res/swf/"+"upEffect"+".swf";
			SwfLoader.StartLoad(str,null,addSwfHandle);
			_time.addEventListener(TimerEvent.TIMER,addCDtimes);
//			if( _bindBuyIndex	==	-1)
//			{
//				_bindIndex	=	_bind.BindProp(_model.scene.Role, "TodayBuyHerbCount", this, "onHerbBuyHandle");
//			}
		}
		public function addSwfHandle(mcv:MovieClip,pL:Array):void
		{	
			effectMC			=	mcv;
			effectMC.gotoAndStop(1);
			effectMC.visible	=	false;
			ui._viweGruop.addChild(effectMC);
		}
		
		public function AfterHide():void
		{
			_time.stop();
			removeEvent();
		}
		
		/**
		 * CD 
		 * @param e
		 * 
		 */		
		private function addCDtimes(e:TimerEvent):void
		{
			_CDTimeCount--;
			if(_CDTimeCount	<= 0)
			{
				_time.stop();
				//ui.timeLab.visible	=	false;
			}
			
			if(_isShowTime)
			{
				_tipsStr		=	StaticIni.getSwfLangStrVar("UIString_1000289",
									[PlayCDTimerLogic.getInstance().getTimerStr(_CDTimeCount,true)]);
				var str:String	=	StaticIni.getSwfLangStr("UIString_1000251");
				str	=	str.concat("<br>");
				str	=	str.concat(_tipsStr);
				TipsManage.showTips(str);
			}
			//ui.timeLab.htmlText	=	PlayCDTimerLogic.getInstance().getTimerStr(_CDTimeCount,true);
		}
		
		/**
		 * 升级师傅 
		 * @return 
		 * 
		 */	
		private function onUpClickHandle(e:MouseEvent):void
		{
			_isShowEff			=	true;
			var num:int			=	_emulateLevelArr[_index];
			var money:int;
			var str:String;
			var temp:int		=	_index;
			if(num > 2)return
			if(num <= 1)
			{
				//money	=	300;
				str		=	StaticIni.getSwfLangStrVar("UIString_1000509",[300])	
			}
			else
			{
				//money	=	1000;
				str		=	StaticIni.getSwfLangStrVar("UIString_1000510",[1000])
			}
			showAler(str ,
					  CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_UPGRADE_PRACTISEROOM,
					  [temp+1] );
		}
		
		/**
		 * 提示框
		 * @param str 提示内容
		 * @param customStr 消息号
		 * @param arr 填充数据
		 * 
		 */		
		private function showAler(str:String,customFlag:Number,arr:Array):void
		{
			var	yesBtnT	:String			=	StaticIni.getSwfLangStr("SellUI_Sure");
			var	noBtn	:String			=	StaticIni.getSwfLangStr("AlertEx_1");
			AlertUI.showAlertEx("",str,
				[yesBtnT,noBtn],AlertUI.YES|AlertUI.NO,clickClearCD);
			function clickClearCD( type:int, str:String, clickData:* ):void
			{
				if(AlertUI.YES == type )
				{
					ui.clearCDbtn.visible	=	false;
					_CDtimeArr[_index]		=	0;
					SystemSender.getInstance().CustomMsgEx(customFlag,arr);
				}
			}
		}
		
		/**
		 * 升级师傅tips
		 * @param e
		 * 
		 */		
		private function onbtn1OverHandle(e:MouseEvent= null):void
		{
			var num:int	=	_emulateLevelArr[_index];
			var money:int;
			if(num > 2)return
			if(num <= 1)
			{
				money	=	300
			}
			else
			{
				money	=	1000
			}
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000228",[money]);
			TipsManage.showTips(str);
		}
//		private function upTeacherTips():void
//		{
//			
//		}
		/**
		 *  打开拜师界面
		 * @return 
		 * 
		 */		
		private function onOpenClickHandle(e:MouseEvent):void
		{
			//var mc:MovieClip	=	e.currentTarget as MovieClip;
			_teacherindex	=	_index;
			if( _emulateLevelArr.length <= 0 )return;
			EmulatePartnerLogic.getInstance().showUI(_index,_emulateLevelArr[_index]);
			//SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_BUY_HERB);
		}
		
		/**
		 * 拜师按钮tips
		 * @param e
		 * 
		 */		
		private function onbtn2OverHandle(e:MouseEvent):void
		{
			var str:String	=	StaticIni.getSwfLangStr("UIString_1000227");
			TipsManage.showTips(str);
		}
		
		/**
		 * 开启按钮tips
		 * @param e
		 * 
		 */		
		private function onbtn3OverHandle(e:MouseEvent):void
		{
			//var val:int		=	_teacherArr.length
			var arr:Array	=	[50,100,200,400,600,800,1000];
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000231",[arr[_CDtimeArr.length-1]]);
			TipsManage.showTips(str);
		}
		
		
		/**
		 *  
		 * @param e
		 * 
		 */		
		private function onImgOverHandle(e:MouseEvent):void
		{
			//var val:int		=	_teacherArr.length;
			_isShowTime	=	true;	
			if(_CDTimeCount > 0)return;
			var str:String	=	StaticIni.getSwfLangStr("UIString_1000251");
			//str	=	str.concat("<br>");
			//var cdStr:String	=	StaticIni.getSwfLangStrVar("UIString_1000289",[_CDTimeCount]);
			//str	=	str.concat(cdStr);
			TipsManage.showTips(str);
		}
		
		
		/**
		 * 关闭tips
		 * @param e
		 * 
		 */		
		private function onCloseTipsHandle(e:MouseEvent):void
		{
			TipsManage.hideTips();
			_isShowTime		=	false;
			_isOnBuyBtn		=	false;
		}
		
		
		/**
		 * 开启新队列 
		 * @param e
		 * 
		 */		
		private function onOpenNewListHandle(e:MouseEvent):void
		{
			var arr:Array	=	[50,100,200,400,600,800,1000];
			showAler( StaticIni.getSwfLangStrVar("UIString_1000503",[arr[_CDtimeArr.length-1]]),
					  CustomToServerFlag.CLIENT_CUSTOMMSG_ADD_CD_QUEUE,
					  [5] );
//			SystemSender.getInstance().CustomMsgEx(
//				CustomToServerFlag.CLIENT_CUSTOMMSG_ADD_CD_QUEUE,[5]);	
			LogSendLogic.getInstance().btnClickNumSend(22809);
		}
		
		/**
		 * 清除CD
		 * @param e
		 * 
		 */		
		private function onClearCDHandle(e:MouseEvent):void
		{
			if(_CDtimeArr[_index] <= 0)return
			var num:int			=	Math.floor(_CDtimeArr[_index]/60);
			var temp:int		=	_index;
			showAler( StaticIni.getSwfLangStrVar("UIString_1000306",[Math.floor(num*0.5)+1]),
					  CustomToServerFlag.CLEINT_CUSTOMMSG_REQUEST_CLEAR_CD,
					  [5,temp+1] );
		}
		
		/**
		 * 清除cd Tips
		 * @param e
		 * 
		 */		
		private function onClearCDOverHandle(e:MouseEvent):void
		{
			if(_CDtimeArr[_index] <= 0)
			{
				btnMcShow();
				return
			}
			var num:int		=	Math.floor(_CDtimeArr[_index]/60);		
			var money:int	=	_model.scene.Role.GetProperties("GoldCoin");
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000305",[Math.floor(num * 0.5)+1,money]);
			TipsManage.showTips(str);
		}
		
		/**
		 * 判断师傅等级师傅升满 
		 * 
		 */		
		private function btnMcShow():void
		{
			var level:int			=	_emulateLevelArr[_index];
			ui.clearCDbtn.visible	=	false;
			_btnMc.visible			=	true;
			if(level == 3)
			{
				(_btnMc.getChildAt(1) as NxButton).x		=	50;
				(_btnMc.getChildAt(0) as NxButton).visible	=	false;
			}
			else
			{
				(_btnMc.getChildAt(1) as NxButton).x		=	20;
				(_btnMc.getChildAt(0) as NxButton).visible	=	true;
			}
		}
		/**
		 * 鼠标滑过师傅头像 
		 * @return 
		 * 
		 */		
		private function onMouseOverHandle(e:MouseEvent):void
		{
			//e.stopPropagation();
			var mc:MovieClip	=	e.currentTarget as MovieClip;
			_btnMc.visible	=	false;
			ui.clearCDbtn.visible	=	false;
			_index			=	-2;
			if(mc.currentFrame == 1)return;
			_btnMc.x		=	mc.x;
			_btnMc.y		=	mc.y;
			_index			=	mc["data"];
		//	var level:int	=	_emulateLevelArr[_index];
			var timeNum:int	=	_CDtimeArr[_index];
			if(timeNum <= 0)
			{	
//				ui.clearCDbtn.visible	=	false;
//				_btnMc.visible	=	true;
//				if(level == 3)
//				{
//					(_btnMc.getChildAt(1) as NxButton).x		=	50;
//					(_btnMc.getChildAt(0) as NxButton).visible	=	false;
//				}
//				else
//				{
//					(_btnMc.getChildAt(1) as NxButton).x		=	20;
//					(_btnMc.getChildAt(0) as NxButton).visible	=	true;
//				}
				btnMcShow();
			}
			else
			{
				ui.clearCDbtn.visible	=	true;
				var checkMc:MovieClip 	=	mc.getChildByName("pic") as MovieClip
				checkMc.addChild(ui.clearCDbtn);
				ui.clearCDbtn.x			=	checkMc.getChildByName("timetxt").x+52;
				ui.clearCDbtn.y			=	checkMc.getChildByName("timetxt").y-2;
				
			}
		}
		
		
		/**
		 * 鼠标离开此界面
		 * @return 
		 * 
		 */		
		private function onMouseOutHandle(e:MouseEvent):void
		{
			var mc:MovieClip	=	e.currentTarget as MovieClip;
			_btnMc.visible	=	false;
			ui.clearCDbtn.visible	=false;
			_index	=	-2;
		}
		
		/**
		 * 得到武学心得价格 
		 * @param e
		 * 
		 */		
		private function getPriceHandle(e:CustomMsgEvent):void
		{
//			var	yesBtnT		:String			=	StaticIni.getSwfLangStr("SellUI_Sure");
//			var	noBtn		:String			=	StaticIni.getSwfLangStr("AlertEx_1");
//			AlertUI.showAlertEx("",StaticIni.getSwfLangStrVar("UIString_1000230",[e.pList[0]]),
//						[yesBtnT,noBtn],AlertUI.YES|AlertUI.NO,clickClearCD);
//			function clickClearCD( type:int, str:String, clickData:* ):void
//			{
//				if(AlertUI.YES == type )
//				{
//					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_BUY_HERB);
//				}
//			}
			var str:String	=	StaticIni.getSwfLangStrVar("UIString_1000230",[e.pList[0]])
			TipsManage.showTips(str);
		}
		
		/**
		 * 武学心得CD时间
		 * @param e
		 * Plist[0] 0 隐藏 1 显示
		 * Plist[1] CD时间
		 */		
		private function onCDtimeHandle(e:CustomMsgEvent):void
		{
			if(e.pList[0] == 0)
			{
				_CDTimeCount	=	0;
				return;
			}
			_CDTimeCount	=	e.pList[1];
			//ui.timeLab.visible	=	true;
			_time.start();
		}
		
		/**
		 * 伙伴获得经验 
		 * @param e
		 * 
		 */		
		private function partnerGetEpHandle(e:CustomMsgEvent):void
		{
			var mc:MovieClip			=	ui._viweGruop.getItemByIndex(_teacherindex);
			//mc.addChild(ui.getExpLab);
			ui.succeedEffect.x			=	mc.x+10;
			ui.succeedEffect.y			=	mc.y-35;
			ui.succeedEffect.visible	=	true;
			ui.succeedEffect.gotoAndPlay(1);
			ui.succeedEffect.addFrameScript(ui.succeedEffect.totalFrames - 1,succeedmcOverHandle);
			
			var mcX:Number		=	mc.x+ui._viweGruop.x+30;
			var mcY:Number		=	mc.y+ui._viweGruop.y+20;
			var tpoint:Point			=	new Point(mcX,mcY);
			ui.getExpLab.visible		=	true
			ui.getExpLab.x				=	tpoint.x;
			ui.getExpLab.y				=	tpoint.y+50;
			ui.getExpLab.htmlText		=	StaticIni.getSwfLangStrVar("UIString_1000307",[e.pList[0],e.pList[1]]);
			TweenLite.to(ui.getExpLab,getDistance()/30,{x:tpoint.x,y:tpoint.y,onComplete:endRun});
			function getDistance():Number
			{
				var p:Point=new Point(mcX,mcY+50);
				return Point.distance(p,tpoint);
			}
		}
		
		private function endRun():void
		{
			ui.getExpLab.visible	=	false
		}
		
		/**
		 *特效播完后的操作 
		 * 
		 */		
		private function mcOverHandle():void
		{
			effectMC.stop();
			effectMC.visible	=	false;
		}
		
		/**
		 * 拜师成功特效播完后的操作 
		 * 
		 */		
		private function succeedmcOverHandle():void
		{
			ui.succeedEffect.stop();
			ui.succeedEffect..visible	=	false;
		}
		
		/**
		 * 请求购买武学心得 
		 * @param e
		 * 
		 */		
//		private function onBuyBookHandle(e:MouseEvent):void
//		{
//			if(_herbNum < _herbMaxNum)
//			{
//				//SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_HERB_PRICE);	
//				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_BUY_HERB);
//			}
//			else
//			{
//				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("97333"))
//			}
//			LogSendLogic.getInstance().btnClickNumSend(22810);
//			
//		}
		
		/**
		 * 购买按钮Tips 
		 * @param e
		 * 
		 */		
//		private function onBuyBookOverHandle(e:MouseEvent=null):void
//		{
//			_isOnBuyBtn	=	true;
//			var str:String;	
//			_herbNum	=	_model.scene.Role.GetProperties("HerbNum");
//			if(_herbNum < _herbMaxNum)
//			{
//				str	=	StaticIni.getSwfLangStrVar("UIString_1000230",[countNeedMoney()])
//				TipsManage.showTips(str);		
//			}
//			else
//			{
//				TipsManage.showTips(StaticIni.getSwfLangStr("97333"));
//			}
//			
//		}
		
		/**
		 * 计算需要消耗多少元宝 
		 * 
		 */		
//		private function countNeedMoney():int
//		{
//			var num:int;
//			if(_buyherbNum < 10)
//			{
//				num 	=	2 + _buyherbNum*2
//			}
//			else
//			{
//				num			=	20;
//			}
//			return num
//		}
		
		/**
		 * 
		 */		
		private function removeEvent():void
		{
			//ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			//ui.buyBtn.removeEventListener(MouseEvent.CLICK,onBuyBookHandle);
		//	ui.buyBtn.removeEventListener(MouseEvent.ROLL_OVER,onBuyBookOverHandle);
		//	ui.buyBtn.removeEventListener(MouseEvent.ROLL_OUT,onCloseTipsHandle);
			ui._viweGruop.removeEventListener(MouseEvent.ROLL_OUT,onMouseOutHandle);
		}
		private function onClickClose(e:Event):void
		{
			ui.hide();
		}
	}
}